#include "stdafx.h"
#include "TQuadric.h"
#include "gemat3d.h"
#include "TOpenGL.h"


TExtent TSphere::GetExtent() const
{
	return TExtent(AcGePoint3d(m_center.x + m_radius, m_center.y + m_radius, m_center.z + m_radius),
		AcGePoint3d(m_center.x - m_radius, m_center.y - m_radius, m_center.z - m_radius));
}

void TSphere::DrawMySelf( TOpenGL *pGL ) const
{
	pGL->GlPushMatrix();
	{
		pGL->GlTranslated(m_center);
		pGL->GluSphere(m_radius, QUADRIC_SLICE, QUADRIC_STACK, m_style, m_normal, m_orientation, m_texture);
	}	
	pGL->GlPopMatrix();
}

void TSphere::TransformBy( const AcGeMatrix3d &mat )
{
	m_center.transformBy(mat);
}
TExtent TCylinder::GetExtent() const
{
	double r = m_base > m_top ? m_base : m_top;
	AcGePoint3d ptMax(r, r, m_height), ptMin(-r, -r, 0);
	AcGeVector3d v = m_center - AcGePoint3d::kOrigin;
	ptMin += v, ptMin += v;

	AcGeMatrix3d matrix;
	matrix.setToIdentity();
	matrix.setToRotation(m_angle, m_axis, m_center);

	ptMin.transformBy(matrix);
	ptMax.transformBy(matrix);

	return TExtent(ptMax, ptMin);
}

void TCylinder::DrawMySelf( TOpenGL *pGL ) const
{
	pGL->GlPushMatrix();
	{
		pGL->GlTranslated(m_center);
		pGL->GlRotated(m_angle, m_axis);
		pGL->GluCylinder(m_base, m_top, m_height, QUADRIC_SLICE, QUADRIC_STACK, m_style, m_normal, m_orientation, m_texture);
	}
	pGL->GlPopMatrix();
}

void TCylinder::TransformBy( const AcGeMatrix3d &mat )
{
	m_center.transformBy(mat);
}
TExtent TDisk::GetExtent() const
{
	AcGePoint3d ptMax(m_outer, m_outer, 0.), ptMin(-m_outer, -m_outer, 0.);
	AcGeVector3d v = m_center - AcGePoint3d::kOrigin;
	ptMin += v, ptMax += v;

	AcGeMatrix3d matrix;
	matrix.setToIdentity();
	matrix.setToRotation(m_angle, m_axis, m_center);

	ptMax.transformBy(matrix);
	ptMin.transformBy(matrix);

	return TExtent(ptMax, ptMin);
}

void TDisk::DrawMySelf( TOpenGL *pGL ) const
{
	pGL->GlPushMatrix();
	{
		pGL->GlTranslated(m_center);
		pGL->GlRotated(m_angle, m_axis);
		pGL->GluDisk(m_inner, m_outer, QUADRIC_SLICE, QUADRIC_LOOPS, m_style, m_normal, m_orientation, m_texture);
	}
	pGL->GlPopMatrix();
}

void TDisk::TransformBy( const AcGeMatrix3d &mat )
{
	m_center.transformBy(mat);
}